package 栈.middle;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Stack;

/**
 * @author Lw中
 * @date 2020/10/18 14:51
 */
public class QiSanJiu {

    /**
     * LWZ TODO : 2020/10/18 没有看懂
     *
     */

    /**
     * 每日温度
     * @param T
     * @return
     */
    public static int[] dailyTemperatures(int[] T) {
        int i = T.length;
        int[] arr = new int[i];
        Deque<Integer> stack = new LinkedList<>();
        for (int j = 0; j < i; j++) {
            int temperature = T[j];
            while (!stack.isEmpty() && temperature > T[stack.peek()]) {
                // 获取前一天的下标
                int preIndex = stack.pop();
                arr[preIndex] = j - preIndex;
            }
            stack.push(j);
        }
        return arr;
    }

    public static void main(String[] args) {
        int[] arr = {73, 74, 75, 71, 69, 72, 76, 73};
        int[] ints = dailyTemperatures(arr);
        System.out.println(Arrays.toString(ints));
    }

}
